package com.itheima.solr;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrTest {
    @Test
    public void test() throws IOException, SolrServerException {
        //访问SolrServe
       SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");

       //创建文档
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id","001");
        document.addField("title","solrJ测试");
        document.addField("price","1885647");

        //添加文档
        solrServer.add(document);

        //提交
        solrServer.commit();
    }
    @Test
    public void testupdate() throws IOException, SolrServerException {
        //访问SolrServe
       SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");

       //创建文档
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id","001");
        document.addField("title","solrJ测试修改的");
        document.addField("price","187654522");

        //添加文档到solr服务器中
        solrServer.add(document);

        //提交
        solrServer.commit();
    }
}
